package com.dynamic.model.service.impl;

import java.util.List;

import javax.annotation.Resource;

import com.dynamic.model.common.dao.BaseDao;
import com.dynamic.model.dao.SystemRoleDao;
import com.dynamic.model.model.po.SysmanRole;
import com.dynamic.model.model.po.SysmanUser;
import com.dynamic.model.service.SystemRoleService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

import com.dynamic.model.common.service.impl.BaseServiceImpl;
import com.dynamic.model.common.vo.Page;

/**
 * 
 * @desc 用户后台登陆用户角色表--RBAC权限管理service接口实现类
 *
 * @author luwei
 * @Fri Aug 08 14:27:52 CST 2014
 */
@Service
public class SystemRoleServiceImpl extends BaseServiceImpl<SysmanRole> implements SystemRoleService {

	@Override
	@Resource(name ="systemRoleDaoImpl")
	public void setBaseDao(BaseDao<SysmanRole> dao) {
		this.baseDao =  dao;
	}
	
	private SystemRoleDao getDao(){
		return (SystemRoleDao) this.baseDao ;
	}

	@Override
	public List<SysmanRole> getPageDataByName(Page<SysmanRole> page, String rolename) {
		Subject subject = SecurityUtils.getSubject();
		SysmanUser user = (SysmanUser) subject.getPrincipal();
		return this.getDao().getPageDataReqName(page,rolename,user.getPid());
	}
	
	@Override
	public void save(SysmanRole entity) throws Exception {
		Subject subject = SecurityUtils.getSubject();
		SysmanUser user = (SysmanUser) subject.getPrincipal();
		entity.setCreater(user.getPid());
		entity.setRoleType(1);
		this.getBaseDao().save(entity);
	}

	@Override
	public void update(SysmanRole entity) throws Exception {
		Subject subject = SecurityUtils.getSubject();
		SysmanUser user = (SysmanUser) subject.getPrincipal();
		entity.setCreater(user.getPid());
		entity.setRoleType(1);
		this.getBaseDao().update(entity);
	}


}
